package mc0101.mccache.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration("zcCacheThreadPoolTaskConfig")
public class ThreadPoolTaskConfig {
    @Value("${cache.threadpooltask.corepoolsize:1}")
    private int corepoolsize;

    @Value("${cache.threadpooltask.maxpoolsize:1}")
    private int maxpoolsize;

    @Value("${cache.threadpooltask.queuecapacity:0}")
    private int queuecapacity;

    /**
     * 消费者控制程序要用的线程池
     * @return
     */
    @Bean(name = "zcCacheThreadPoolTaskExecutor")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor tmPoolTaskExecutor = new ThreadPoolTaskExecutor();
        tmPoolTaskExecutor.setCorePoolSize(corepoolsize);
        tmPoolTaskExecutor.setMaxPoolSize(maxpoolsize);
        tmPoolTaskExecutor.setQueueCapacity(queuecapacity);//队列最大长度
        return tmPoolTaskExecutor;
    }
}